import os.path
import time
import unittest
from HTMLTestRunner import HTMLTestRunner

# loader
discover = unittest.defaultTestLoader.discover('test_cases', 'test*')

# runner
# 准备要写入的文件
# 文件名规则:年月日时分秒-login.html
report = os.path.abspath('report')
filename = time.strftime('%Y%m%d%H%M%S') + '-demo.html'
filepath = os.path.join(report, filename)

# 写入文件
with open(filepath, 'wb') as f:
    runner = HTMLTestRunner(
        title='测试报告标题',  # 测试报告标题
        stream=f,  # 导入测试报告
        verbosity=2,  # 测试报告详细程度
        tester='坤坤',  # 作者名
        description='测试报告副标题'  # 测试报告副标题
    )
    runner.run(discover)
